<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Pointlist extends CI_Controller {
	public function __construct(){
								parent::__construct();
								//$this->load->model(array("pointmodel"));
				}

					public function index()
					{

				        $data=array();
						load($this->db,$this->session,$this->load,"pointlist","home",$data);
					}


				

					public function get_area(){//获取所有地区列表
						$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
						$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
						$offset = ($page-1)*$rows;
						 $arr=$this->settingmodel->get_area($offset,$rows);

										 $str=json_encode($arr);
										 echo $str;
					}




            public function get_point_list(){
            	     $arr=read_point_list($this->db,'-1');
            	      $str=json_encode($arr);

            	      echo $str;
            }

             

           public function save_point(){
           	$parent=$this->input->post("parent");
           	$name=$this->input->post("name");
           		$jarea=$this->input->post("jarea");
           	$jcity=$this->input->post("jcity");
           	$jcounty=$this->input->post("jcounty");
           	$address=$this->input->post("address");
           	$mobile=$this->input->post("mobile");
           	$contact=$this->input->post("contact");
           	$arr=array("parent"=>$parent,"name"=>$name,"jarea"=>$jarea,"jcity"=>$jcity,"jcounty"=>$jcounty,"address"=>$address,"mobile"=>$mobile,"contact"=>$contact);
           	if($this->db->insert("point",$arr)){
		           	ajaxsuccess();
		           }else{
		           	ajaxfail();
		           }

           }


           public function save_point_list(){
            $parent=$this->input->post("parent");
            $name=$this->input->post("name");
            $arr=array("parent"=>$parent,"name"=>$name);
            if($this->db->insert("point_list",$arr)){
                ajaxsuccess();
               }else{
                ajaxfail();
               }

           }

           public function save_edit_point_list(){
           	$id=$this->input->post("id");
           	$name=$this->input->post("name");
           	// $jarea=$this->input->post("jarea");
           	// $jcity=$this->input->post("jcity");
           	// $jcounty=$this->input->post("jcounty");
           	// $address=$this->input->post("address");
           	// $mobile=$this->input->post("mobile");
           	// $contact=$this->input->post("contact");
           	$sql="update point_list set name='$name' where id='$id'";
           	if($this->db->query($sql)){
		           	ajaxsuccess();
		           }else{
		           	ajaxfail();
		           }

           }


           public function del_point_list(){
           	$id=$this->input->post("id");

           	$sql="delete from point_list where id='$id'";

           	if($this->db->query($sql)){
           		ajaxsuccess();
           	}else{
           		ajaxfail();
           	}
           }


            public function get_area_list(){
                  $parent_id=$_GET['parent_id'];
                if(empty($parent_id)){
                  $parent_id=0;
                }
                  $sql="select * from area where area_parent_id='$parent_id'";
                  $query=$this->db->query($sql);
                  $arr=$query->result_array();
                  $str=json_encode($arr);
                  echo $str;
                }



                 public function get_area_main(){
                  $parent_id=$_GET['parent_id'];
                if(empty($parent_id)){
                  $parent_id=0;
                }
                  $sql="select * from area where area_parent_id='$parent_id'";
                  $query=$this->db->query($sql);
                  $arr=$query->result_array();
                  $str=json_encode($arr);
                  echo $str;
                }


                public function get_area_deep(){
                  $area_deep=$_GET['area_deep'];
                if(empty($parent_id)){
                  $parent_id=0;
                }
                  $sql="select * from area where area_deep='$area_deep'";
                  $query=$this->db->query($sql);
                  $arr=$query->result_array();
                  $str=json_encode($arr);
                  echo $str;
                }


}
